package com.gh.rabbitmq.five;

import com.gh.rabbitmq.utils.RabbitmqUtils;
import com.rabbitmq.client.Channel;

import java.util.Scanner;

/**
 * @Author Eric
 * @Date 2021/7/18 14:17
 * @Version 1.0
 * 发消息给交换机
 */
public class Emit01 {
    public static final String EXCHANGE_NAME="logs";

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitmqUtils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME,"fanout");
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.nextLine();
            channel.basicPublish(EXCHANGE_NAME,"",null,message.getBytes());
            System.out.println("生产者发出消息:"+message);
        }
    }
}
